<template>
  <div class="order-list-item" v-if="item.orderId">
    <div class="tit">
      <div class="time">订单编号：{{ item.orderNo }}</div>
      <div class="status">
        <span>{{ item.stateText }}</span>
      </div>
    </div>
    <!-- <div class="list" >
      <div class="list-item" v-for="(goods, index) in item.goods" :key="index">
        <div class="goods-img">
          <img :src="goods.goods_image" alt="">
        </div>
        <div class="goods-content text-ellipsis-2">
          {{ goods.goods_name }}
        </div>
        <div class="goods-trade">
          <p>¥ {{ goods.total_pay_price }}</p>
          <p>x {{ goods.total_num }}</p>
        </div>
      </div>
    </div> -->
    <div class="list" >
      <div class="list-item">
        <div class="goods-img">
          <img :src="item.goods.goods_image" alt="">
        </div>
        <div class="goods-content text-ellipsis-2">
          {{ item.goods.goods_name }}
        </div>
        <div class="goods-trade">
          <p>¥ {{ totalPayPrice }}</p>
          <p>x {{ item.goodsNum }}</p>
        </div>
      </div>
    </div>
    <div class="total">
      共 {{ item.goodsNum }} 件商品，总金额 ¥{{ totalPayPrice }}
    </div>
    <div class="actions">
      <div v-if="item.orderStatus === '10'">
        <span v-if="item.payStatus === '10'" @click="payOrder(item.orderId)">立刻付款</span>
        <span v-else-if="item.deliveryStatus === '10'" @click="applyCancelOrder(item.orderId)">申请取消</span>
        <span v-else-if="item.deliveryStatus === '20' || item.deliveryStatus === '30'" @click="confirmReceipt(item.orderId)">确认收货</span>
      </div>
      <div v-if="item.orderStatus === '20'">
        <span @click="deleteOrder(item.orderId)">删除订单</span>
      </div>
      <div v-if="item.orderStatus === '30'">
        <span>评价</span>
      </div>
    </div>
  </div>
</template>

<script>
import { payOrder, applyCancelOrder, confirmReceipt, deleteOrder } from '@/api/order'
export default {
  props: {
    item: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  computed: {
    totalPayPrice () {
      return this.item.goodsNum * this.item.goods.goods_price_min
    }
  },
  methods: {
    // 提供getPersonMyOrderList的实例方法，无具体逻辑
    getPersonMyOrderList () {

    },
    getMyOrderList () {
      this.$emit('getPersonMyOrderList')
    },
    async payOrder (orderId) {
      await payOrder(orderId)
      // 重新渲染order列表
      this.getMyOrderList()
    },
    async applyCancelOrder (orderId) {
      await applyCancelOrder(orderId)
      // 重新渲染order列表
      this.getMyOrderList()
    },
    async confirmReceipt (orderId) {
      await confirmReceipt(orderId)
      // 重新渲染order列表
      this.getMyOrderList()
    },
    async deleteOrder (orderId) {
      await deleteOrder(orderId)
      // 重新渲染order列表
      this.getMyOrderList()
    }
  }
}
</script>

<style lang="less" scoped>
.order-list-item {
  margin: 10px auto;
  width: 94%;
  padding: 15px;
  background-color: #ffffff;
  box-shadow: 0 0.5px 2px 0 rgba(0,0,0,.05);
  border-radius: 8px;
  color: #333;
  font-size: 13px;

  .tit {
    height: 24px;
    line-height: 24px;
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    .status {
      color: #fa2209;
    }
  }

  .list-item {
    display: flex;
    .goods-img {
      width: 90px;
      height: 90px;
      margin: 0px 10px 10px 0;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .goods-content {
      flex: 2;
      line-height: 18px;
      max-height: 36px;
      margin-top: 8px;
    }
    .goods-trade {
      flex: 1;
      line-height: 18px;
      text-align: right;
      color: #b39999;
      margin-top: 8px;
    }
  }

  .total {
    text-align: right;
  }
  .actions {
    text-align: right;
    span {
      display: inline-block;
      height: 28px;
      line-height: 28px;
      color: #383838;
      border: 0.5px solid #a8a8a8;
      font-size: 14px;
      padding: 0 15px;
      border-radius: 5px;
      margin: 10px 0;
    }
  }
}
</style>
